Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(string id)
        {
            MasCity masCity = db.MasCities.Find(id);

            db.MasCities.Remove(masCity);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "WSysCode,WSysCreateCode,WSysCreateUtc,WSysUpdateCode,WSysUpdateUtc,WSysStatusFlg,WSysIsDelete,WCountryCode,WName")] MasCity masCity)
 {
     if (ModelState.IsValid)
     {
         db.Entry(masCity).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(masCity));
 }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "WSysCode,WSysCreateCode,WSysCreateUtc,WSysUpdateCode,WSysUpdateUtc,WSysStatusFlg,WSysIsDelete,WCountryCode,WName")] MasCity masCity)
        {
            if (ModelState.IsValid)
            {
                db.MasCities.Add(masCity);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(masCity));
        }
Exemplo n.º 4
0
        // GET: Root/MasCities/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MasCity masCity = db.MasCities.Find(id);

            if (masCity == null)
            {
                return(HttpNotFound());
            }
            return(View(masCity));
        }
Exemplo n.º 5
0
        public ApiModel Update(MasCity model)
        {
            // Check existed record by update date
            var currentEntry = this.ReadOne(model.WSysCode, model.WSysUpdateUtc);

            // Return api model
            var apiModel = new ApiModel();

            if (currentEntry == null)
            {
                apiModel.RtnMessage = "The data has been update by another user. Please reload page."; //TODO

                return(apiModel);
            }

            // Check status
            if ((int)RepoConst.WSysStatus.Delete == model.WSysStatusFlg)
            {
                model.WSysIsDelete = (int)RepoConst.WSysIsDelete.Yes;
            }

            // Get UTC datetime
            var utcNow = DateTime.UtcNow;

            // Init data
            model.WSysUpdateCode = "login code"; // TODO
            model.WSysUpdateUtc  = utcNow;

            try
            {
                // To database
                this.DbRepository.Entry(currentEntry).CurrentValues.SetValues(model);
                this.DbRepository.Entry(currentEntry).State = EntityState.Modified;

                // Save update data
                this.DbRepository.SaveChanges();

                apiModel.RtnData = model.WName;
            }
            catch (Exception ex)
            {
                LogProvider.Instance.LogError(ex);
                apiModel.RtnCode    = (int)RepoConst.ApiState.False;
                apiModel.RtnMessage = ex.InnerException == null ? ex.Message : ex.InnerException?.Message;
            }

            return(apiModel);
        }
Exemplo n.º 6
0
        public ApiModel ReadOne(MasCity model)
        {
            // Return api model
            var apiModel = new ApiModel();

            try
            {
                // Add to database
                apiModel.RtnData    = this.DbRepository.MasCities.Where(entry => entry.WSysCode == model.WSysCode).FirstOrDefault();
                apiModel.RtnMessage = this.DbRepository.MasCities.Where(entry => entry.WSysCode == model.WSysCode).Count().ToString();
            }
            catch (Exception ex)
            {
                LogProvider.Instance.LogError(ex);
                apiModel.RtnCode    = (int)RepoConst.ApiState.False;
                apiModel.RtnMessage = ex.InnerException == null ? ex.Message : ex.InnerException?.Message;
            }

            return(apiModel);
        }
Exemplo n.º 7
0
        public ApiModel Create(MasCity model)
        {
            // Get UTC datetime
            var utcNow = DateTime.UtcNow;

            // Model Code
            model.WSysCode = RepoUtility.GuidCode();

            // Init data
            model.WSysStatusFlg  = (int)RepoConst.WSysStatus.Active;
            model.WSysIsDelete   = (int)RepoConst.WSysIsDelete.No;
            model.WSysCreateCode = "login code"; // TODO
            model.WSysCreateUtc  = utcNow;
            model.WSysUpdateCode = "login code"; // TODO
            model.WSysUpdateUtc  = utcNow;

            // Return api model
            var apiModel = new ApiModel();

            try
            {
                // To database
                this.DbRepository.MasCities.Add(model);

                // Save data
                this.DbRepository.SaveChangesAsync();

                apiModel.RtnData = model.WName;
            }
            catch (Exception ex)
            {
                LogProvider.Instance.LogError(ex);
                apiModel.RtnCode    = (int)RepoConst.ApiState.False;
                apiModel.RtnMessage = ex.InnerException == null ? ex.Message : ex.InnerException?.Message;
            }

            return(apiModel);
        }