Exemplo n.º 1
0
        public HttpResponseMessage PostCreate([FromBody] Contract_VM c)
        {
            if (!IsConnected())
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "You must be connected"));
            }
            long portfolioId = portfolioRepository.GetByFilter(p => p.Sector.Equals(c.Sector)).First().Id;
            //string zone = LDAPService.Instance.GetLDAPUser(HttpContext.Current.Session["Username"].ToString()).Zone;

            /* string zone = "France";
             *
             * var zonesFromDbs = geographicalZoneRepository.GetByFilter(z => z.Id.Equals(1));
             *
             * var selectedZones = new List<GeographicalZone>();
             * zonesFromDbs.ToList().ForEach(z => selectedZones.Add(z));*/
            Contract contract = new Contract
            {
                Name        = c.Name,
                InitDate    = Convert.ToDateTime(c.InitDate),
                EndDate     = Convert.ToDateTime(c.EndDate),
                Bonus       = c.Bonus,
                Company     = c.Company,
                PortfolioId = portfolioId,
                //Zones = selectedZones
            };

            contractRepository.Insert(contract);
            contractRepository.SaveChanges();
            return(Request.CreateResponse(HttpStatusCode.Created, "Contract successfully created"));
        }
Exemplo n.º 2
0
        private Contract_VM ContractTOjson(Contract c)
        {
            List <string> g = geographicalZonesTOjson(c.Zones.ToList());
            Portfolio     p = portfolioRepository.GetById(c.PortfolioId);

            Contract_VM c_vm = new Contract_VM()
            {
                Id       = c.Id,
                Name     = c.Name,
                InitDate = c.InitDate.ToString("dd/MM/yyyy"),
                EndDate  = c.EndDate.ToString("dd/MM/yyyy"),
                Bonus    = c.Bonus,
                Company  = c.Company,
                Sector   = p.Sector,
                Zones    = g
            };

            return(c_vm);
        }