158 lines
8.0 KiB
C#
158 lines
8.0 KiB
C#
|
|
using DevExtreme.AspNet.Data;
|
|||
|
|
using DevExtreme.AspNet.Mvc;
|
|||
|
|
using Newtonsoft.Json;
|
|||
|
|
using Newtonsoft.Json.Linq;
|
|||
|
|
using OSS.Models;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Net;
|
|||
|
|
using System.Net.Http;
|
|||
|
|
using System.Net.Http.Formatting;
|
|||
|
|
using System.Web.Http;
|
|||
|
|
|
|||
|
|
namespace OSS.Controllers
|
|||
|
|
{
|
|||
|
|
[Authorize]
|
|||
|
|
[Route("api/CompanyProfile/{action}", Name = "CompanyProfile")]
|
|||
|
|
public class CompanyProfileExternalApiController : ApiController
|
|||
|
|
{
|
|||
|
|
private OSSDBContext myContext = new OSSDBContext();
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetCompanyProfile(DataSourceLoadOptions loadOptions)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.CompanyProfileExternal, loadOptions));
|
|||
|
|
}
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetApplicationAttachments(DataSourceLoadOptions loadOptions ,string ApplicationCode)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.AttachmentsList.Where(t=>t.ProjectCode==ApplicationCode), loadOptions));
|
|||
|
|
}
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetCompanyProfileByTIN(DataSourceLoadOptions loadOptions , string Username)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.CompanyProfileExternal.Where(t=>t.AddedBy==Username), loadOptions));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetIncompleteApp(DataSourceLoadOptions loadOptions, string Username)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.StepsManagements.Where(t => t.CompanyEmail == Username && t.SubmittedStatus=="Not Submitted" && t.ApplicationType=="New"), loadOptions));
|
|||
|
|
}
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetIncompleteAppExtension(DataSourceLoadOptions loadOptions, string Username)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.StepsManagements.Where(t => t.CompanyEmail == Username && t.SubmittedStatus == "Not Submitted" && t.ApplicationType == "Extension"), loadOptions));
|
|||
|
|
}
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetIncompleteAppAmendment(DataSourceLoadOptions loadOptions, string Username)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.StepsManagements.Where(t => t.CompanyEmail == Username && t.SubmittedStatus == "Not Submitted" && t.ApplicationType == "Amendment"), loadOptions));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetIncompleteAppExpansion(DataSourceLoadOptions loadOptions, string Username)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.StepsManagements.Where(t => t.CompanyEmail == Username && t.SubmittedStatus == "Not Submitted" && t.ApplicationType == "Expansion"), loadOptions));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpDelete]
|
|||
|
|
public void Delete(FormDataCollection form)
|
|||
|
|
{
|
|||
|
|
var key = Convert.ToInt32(form.Get("key"));
|
|||
|
|
var model = myContext.AttachmentsList.FirstOrDefault(item => item.AttachmentID == key);
|
|||
|
|
|
|||
|
|
myContext.AttachmentsList.Remove(model);
|
|||
|
|
myContext.SaveChanges();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetProjectsByUserAmendment(DataSourceLoadOptions loadOptions, string Username)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.ApplicationManagers.Where(t => t.CompanyEmail == Username && t.ServiceName == "Amendment").OrderByDescending(t => t.CreatedDate), loadOptions));
|
|||
|
|
}
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetProjectsByUserExtension(DataSourceLoadOptions loadOptions, string Username)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.ApplicationManagers.Where(t => t.CompanyEmail == Username && t.ServiceName == "Extension").OrderByDescending(t => t.CreatedDate), loadOptions));
|
|||
|
|
}
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetProjectsByUser(DataSourceLoadOptions loadOptions, string Username)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.ApplicationManagers.Where(t => t.CompanyEmail == Username && t.ServiceName == "New").OrderByDescending(t => t.CreatedDate), loadOptions));
|
|||
|
|
}
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetInvoiceByUser(DataSourceLoadOptions loadOptions, string ProjectCode)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.ApplicationManagers.Where(t => t.ProjectCode == ProjectCode ).OrderByDescending(t => t.ApplicationID), loadOptions));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetInvoiceByUserAll(DataSourceLoadOptions loadOptions, string ProjectCode)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.ApplicationManagers.Where(t => t.ProjectCode == ProjectCode && (t.ServiceName == "New" || t.ServiceName == "Expansion" || t.ServiceName == "Amendment" || t.ServiceName == "Extension")).OrderByDescending(t => t.CreatedDate), loadOptions));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetInvoiceByUserExpansion(DataSourceLoadOptions loadOptions, string ProjectCode)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.ApplicationManagers.Where(t => t.ProjectCode == ProjectCode && t.ServiceName == "Expansion").OrderByDescending(t=>t.CreatedDate), loadOptions));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetProjectsByUserExpansion(DataSourceLoadOptions loadOptions, string Username)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.ApplicationManagers.Where(t => t.CompanyEmail == Username && t.ServiceName == "Expansion").OrderByDescending(t => t.CreatedDate), loadOptions));
|
|||
|
|
}
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetInvoiceByUserAmendment(DataSourceLoadOptions loadOptions, string ProjectCode)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.ApplicationManagers.Where(t => t.ProjectCode == ProjectCode && (t.ServiceName == "Amendment" || t.ServiceName=="Extension")).OrderByDescending(t => t.CreatedDate), loadOptions));
|
|||
|
|
}
|
|||
|
|
[HttpGet]
|
|||
|
|
public HttpResponseMessage GetApprovedProjectsByUser(DataSourceLoadOptions loadOptions, string Username)
|
|||
|
|
{
|
|||
|
|
return Request.CreateResponse(DataSourceLoader.Load(myContext.ApplicationManagers.Where(t => t.CompanyEmail == Username && t.EvaluationStatus=="Approved").OrderByDescending(t => t.CreatedDate), loadOptions));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
[HttpPost]
|
|||
|
|
public HttpResponseMessage AddCompanyProfile(FormDataCollection form)
|
|||
|
|
{
|
|||
|
|
var values = form.Get("values");
|
|||
|
|
JObject data = JObject.Parse(values);
|
|||
|
|
var newCompanyProfile = new CompanyProfileExternal();
|
|||
|
|
JsonConvert.PopulateObject(values, newCompanyProfile);
|
|||
|
|
Validate(newCompanyProfile);
|
|||
|
|
if (!ModelState.IsValid)
|
|||
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState.GetFullErrorMessage());
|
|||
|
|
myContext.CompanyProfileExternal.Add(newCompanyProfile);
|
|||
|
|
myContext.SaveChanges();
|
|||
|
|
return Request.CreateResponse(HttpStatusCode.Created);
|
|||
|
|
}
|
|||
|
|
[HttpPut]
|
|||
|
|
public HttpResponseMessage UpdateProfile(FormDataCollection form)
|
|||
|
|
{
|
|||
|
|
var key = Convert.ToString(form.Get("key"));
|
|||
|
|
var values = form.Get("values");
|
|||
|
|
var CompanyInfo = myContext.CompanyProfileExternal.First(o => o.CompanyTIN == key);
|
|||
|
|
JObject data = JObject.Parse(values);
|
|||
|
|
values = data.ToString();
|
|||
|
|
JsonConvert.PopulateObject(values, CompanyInfo);
|
|||
|
|
Validate(CompanyInfo);
|
|||
|
|
if (!ModelState.IsValid)
|
|||
|
|
{
|
|||
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState.GetFullErrorMessage());
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
myContext.SaveChanges();
|
|||
|
|
|
|||
|
|
return Request.CreateResponse(HttpStatusCode.OK);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|