public IActionResult Create(ContractCreateModel model)
        {
            var contract = new ContractDTO
            {
                CustomerId              = User.GetRole() == Role.Customer ? User.GetId() : model.UserId,
                PerformerId             = User.GetRole() == Role.Performer ? User.GetId() : model.UserId,
                CreatedDate             = DateTime.Now,
                Status                  = ContractStatus.Proposed,
                ExpirationDate          = model.ExpirationDate,
                ConstructionSiteAddress = model.ConstructionSiteAddress
            };

            foreach (var p in model.Proposals)
            {
                p.AdvertId   = null;
                p.ContractId = null;
                p.Id         = 0;
                contract.JobProposals.Add(p);
            }

            try
            {
                var id = _contractService.Create(contract, User.GetRole());
                return(Ok(id));
            }
            catch (EBValidationException ex)
            {
                ModelState.AddModelError(nameof(model), ex.Message);
                return(BadRequest(ModelState));
            }
        }
Exemple #2
0
        public IHttpActionResult CreateContract(ContractCreateModel contractToCreate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateContractService();

            service.CreateContract(contractToCreate);
            return(Ok());
        }
        public bool Create(ContractCreateModel model)
        {
            // Object Initialization Syntax
            var entity = new ContractData()
            {
                DevId  = model.DevId,
                TeamId = model.TeamId
            };


            using (var ctx = new ApplicationDbContext())
            {
                ctx.Contracts.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public IHttpActionResult Create(ContractCreateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //Instantiate the specific dev service
            var service = LocalContractService();

            //Call the appropriate method
            //passing in the appropiate model
            if (!service.Create(model))
            {
                return(InternalServerError());
            }

            return(Ok(model));
        }
        public void CreateContract(ContractCreateModel contractToCreate)
        {
            int weaponPrice;
            int shipPrice;

            var entity = new Contract()
            {
                ContractDescription = contractToCreate.ContractDescription,
                CharacterId         = contractToCreate.CharacterId,
                PlanetId            = contractToCreate.PlanetId,
            };
            Character character = _ctx.Characters.Single(e => e.CharacterId == contractToCreate.CharacterId);

            if (contractToCreate.ShipId != null)
            {
                entity.ShipId = (int)contractToCreate.ShipId;
                shipPrice     = _ctx.Ships.Find(contractToCreate.ShipId).ShipPrice;
            }
            else
            {
                entity.ShipId = (int)character.DefaultShipId;
                shipPrice     = _ctx.Ships.Find(character.DefaultShipId).ShipPrice;
            }
            if (contractToCreate.WeaponId != null)
            {
                entity.WeaponId = (int)contractToCreate.WeaponId;
                weaponPrice     = _ctx.Weapons.Find(contractToCreate.WeaponId).Price;
            }
            else
            {
                entity.WeaponId = (int)character.DefaultWeaponId;
                weaponPrice     = _ctx.Weapons.Find(character.DefaultWeaponId).Price;
            }
            var characterPrice = _ctx.Characters.Find(contractToCreate.CharacterId).Price;
            var planetPrice    = _ctx.Planets.Find(contractToCreate.PlanetId).Price;

            entity.ContractPrice = characterPrice + planetPrice + shipPrice + weaponPrice;
            _ctx.Contracts.Add(entity);
            _ctx.SaveChanges();
        }