public async Task <bool> AddTechAsync(TechnologyDTO technologyDTO)
        {
            try
            {
                var user = await userManager.FindByEmailAsync(technologyDTO.UserEmail);

                if (user == null)
                {
                    return(false);
                }
                Technology technology = new Technology
                {
                    Name          = technologyDTO.Name,
                    Description   = technologyDTO.Description,
                    ImgSourceLink = technologyDTO.ImgSourceLink,
                    BasicFee      = technologyDTO.BasicFee,
                    Commission    = technologyDTO.Commission,
                    Duration      = technologyDTO.Duration,
                    User          = user
                };
                context.Technologies.Add(technology);

                int result = context.SaveChanges(); // returns number of changes
                if (result > 0)
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                throw;
            }
        }
        public IHttpActionResult Create([FromBody] TechnologyDTO technology)
        {
            ThrowIfUserHasNoRole(createRole);
            if (technology == null)
            {
                throw new KairosException("Missing model parameter");
            }

            if (technology.Technology_PK != 0)
            {
                throw new KairosException("Post method is not allowed because the requested primary key is must be '0' (zero) .");
            }
            using (var technologyCreateHandler = new TechnologyCreateHandler(Db, ActiveUser, new TechnologyValidator(), new TechnologyFactory(Db, ActiveUser), new TechnologyQuery(Db), AccessControl))
            {
                using (var transaction = new TransactionScope())
                {
                    var saveResult = technologyCreateHandler.Save(technologyDTO: technology, dateStamp: DateTime.Now);
                    transaction.Complete();
                    if (saveResult.Success)
                    {
                        return(Ok(new SuccessResponse(saveResult.Model, saveResult.Message)));
                    }
                    return(Ok(new ErrorResponse(ServiceStatusCode.ValidationError, saveResult.ValidationResult, saveResult.Message)));
                }
            }
        }
 public void Update(TechnologyDTO technologyDTO, DateTime dateStamp)
 {
     if (technologyDTO == null)
     {
         throw new ArgumentNullException("Technology model is null.");
     }
     tblM_Technology technology = technologyFactory.CreateFromDbAndUpdateFromDTO(technologyDTO, dateStamp);
 }
        public tblM_Technology Insert(TechnologyDTO technologyDTO, DateTime dateStamp)
        {
            if (technologyDTO == null)
            {
                throw new ArgumentNullException("Technology model is null.");
            }
            tblM_Technology technology = technologyFactory.CreateFromDTO(technologyDTO, dateStamp);

            return(Db.tblM_Technology.Add(technology));
        }
Esempio n. 5
0
        private TechnologyEntryModel GetCreateStateModel()
        {
            TechnologyEntryFormData formData      = new TechnologyEntryFormData();
            List <Control>          formControls  = CreateFormControls(0);
            TechnologyDTO           technologyDTO = new TechnologyDTO();

            return(new TechnologyEntryModel()
            {
                FormData = formData,
                FormControls = formControls,
                Model = technologyDTO,
            });
        }
        public async Task <IActionResult> Post([FromBody] TechnologyDTO technologyDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            bool result = await repository.AddTechAsync(technologyDTO);

            if (result)
            {
                return(Created("AddTech", new { Message = "Technology added successfully" }));
            }
            return(BadRequest(result));
        }
Esempio n. 7
0
        private TechnologyEntryModel GetUpdateStateModel(int technologyPK)
        {
            TechnologyEntryFormData formData      = new TechnologyEntryFormData();
            List <Control>          formControls  = CreateFormControls(technologyPK);
            TechnologyDTO           technologyDTO = technologyQuery.GetByPrimaryKey(technologyPK);

            if (technologyDTO == null)
            {
                throw new KairosException($"Record with primary key '{technologyDTO.Technology_PK}' is not found.");
            }

            return(new TechnologyEntryModel()
            {
                FormData = formData,
                FormControls = formControls,
                Model = technologyDTO,
            });
        }
        public SaveResult <TechnologyEntryModel> Save(TechnologyDTO technologyDTO, DateTime dateStamp)
        {
            ModelValidationResult validationResult = technologyValidator.Validate(technologyDTO);
            bool success = false;
            TechnologyEntryModel model = null;

            if (validationResult.IsValid)
            {
                success = true;
                Update(technologyDTO, dateStamp);
                Db.SaveChanges();
                model = technologyEntryDataProvider.Get(technologyDTO.Technology_PK);
            }

            return(new SaveResult <TechnologyEntryModel>
            {
                Success = success,
                Message = validationResult.IsValid ? "Data successfully updated." : "Validation error occured.",
                Model = model,
                ValidationResult = validationResult
            });
        }
Esempio n. 9
0
        public TechnologyDTO GetByTitle(string title)
        {
            TechnologyDTO record = GetQuery().FirstOrDefault(technology => technology.Title == title);

            return(record);
        }
Esempio n. 10
0
        public TechnologyDTO GetByPrimaryKey(int primaryKey)
        {
            TechnologyDTO record = GetQuery().FirstOrDefault(technology => technology.Technology_PK == primaryKey);

            return(record);
        }