/// <summary>
 ///
 /// </summary>
 /// <param name="model"></param>
 /// <param name="raw"></param>
 /// <returns></returns>
 public static ApplicationUpdateRecord ToModel(this SingleRecord model, ApplicationUpdateRecord raw)
 {
     if (model == null)
     {
         return(null);
     }
     if (raw == null)
     {
         raw = new ApplicationUpdateRecord();
     }
     raw.Create      = model.Create;
     raw.Description = model.Description;
     raw.IsRemoved   = model.IsRemoved;
     raw.Version     = model.Version;
     raw.AppName     = model.AppName;
     return(raw);
 }
Ejemplo n.º 2
0
        public IActionResult AddUpdateVersion([FromBody] ApplicationUpdateRecordUpdateViewModel model)
        {
            var authBy = model.Auth.AuthUser(authService, currentUserService.CurrentUser?.Id);

            if (authBy != "root")
            {
                return(new JsonResult(model.Auth.PermitDenied()));
            }
            var mList = model.Data.List;

            foreach (var m in mList)
            {
                var  r     = context.ApplicationUpdateRecordsDb.Where(rec => rec.Version == m.Version).FirstOrDefault();
                bool isAdd = false;
                if (r == null)
                {
                    if (m.IsRemoved)
                    {
                        return(new JsonResult(r.NotExist()));
                    }
                    r     = new ApplicationUpdateRecord();
                    isAdd = true;
                }
                r = m.ToModel(r);
                if (m.IsRemoved)
                {
                    r.Remove();
                }
                if (isAdd)
                {
                    context.ApplicationUpdateRecords.Add(r);
                }
                else
                {
                    context.ApplicationUpdateRecords.Update(r);
                }
            }
            context.SaveChanges();
            return(new JsonResult(ActionStatusMessage.Success));
        }