Пример #1
0
        public object update([FromBody] JsonElement json)
        {
            var model = JsonConvert.DeserializeObject <Test>(json.GetRawText());

            if (model == null)
            {
                return(CreatedAtAction(nameof(update), new { result = ResultCode.InputHasNotFound, message = ResultMessage.InputHasNotFound }));
            }

            var test = _context.Tests.Where(w => w.Name == model.Name & w.SubjectID == model.SubjectID & w.ID != model.ID).FirstOrDefault();

            if (test != null)
            {
                return(CreatedAtAction(nameof(update), new { result = ResultCode.DuplicateData, message = ResultMessage.DuplicateData }));
            }

            test = _context.Tests.Where(w => w.ID == model.ID).FirstOrDefault();
            if (test != null)
            {
                model.Update_On = DateUtil.Now();
                model.TestCode  = "T" + test.ID.ToString("00000000");
                _context.Entry(test).CurrentValues.SetValues(model);
                _context.SaveChanges();

                return(CreatedAtAction(nameof(update), new { result = ResultCode.Success, message = ResultMessage.Success }));
            }
            return(CreatedAtAction(nameof(update), new { result = ResultCode.InvalidInput, message = ResultMessage.InvalidInput }));
        }
Пример #2
0
        public object modify([FromBody] JsonElement json)
        {
            var model = JsonConvert.DeserializeObject <AttitudeSetup>(json.GetRawText());

            if (model == null)
            {
                return(CreatedAtAction(nameof(modify), new { result = ResultCode.InputHasNotFound, message = ResultMessage.InputHasNotFound }));
            }

            var attitude = _context.AttitudeSetups.Where(w => w.AttitudeAnsType == model.AttitudeAnsType & w.AttitudeAnsSubType == model.AttitudeAnsSubType).FirstOrDefault();

            if (attitude == null)
            {
                model.Create_On = DateUtil.Now();
                model.Update_On = DateUtil.Now();
                model.Create_By = model.Update_By;
                _context.AttitudeSetups.Add(model);
                _context.SaveChanges();
            }
            else
            {
                model.Update_On = DateUtil.Now();
                model.ID        = attitude.ID;
                _context.Entry(attitude).CurrentValues.SetValues(model);
                _context.SaveChanges();
            }

            return(CreatedAtAction(nameof(modify), new { result = ResultCode.Success, message = ResultMessage.Success }));
        }