public IHttpActionResult PosttOrgCluster(tOrgCluster tOrgCluster)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.tOrgClusters.Add(tOrgCluster);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (tOrgClusterExists(tOrgCluster.clusterCode))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = tOrgCluster.clusterCode }, tOrgCluster));
        }
        public IHttpActionResult PuttOrgCluster(string id, tOrgCluster tOrgCluster)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tOrgCluster.clusterCode)
            {
                return(BadRequest());
            }

            db.Entry(tOrgCluster).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tOrgClusterExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GettOrgCluster(string id)
        {
            tOrgCluster tOrgCluster = db.tOrgClusters.Find(id);

            if (tOrgCluster == null)
            {
                return(NotFound());
            }

            return(Ok(tOrgCluster));
        }
        public IHttpActionResult DeletetOrgCluster(string id)
        {
            tOrgCluster tOrgCluster = db.tOrgClusters.Find(id);

            if (tOrgCluster == null)
            {
                return(NotFound());
            }

            db.tOrgClusters.Remove(tOrgCluster);
            db.SaveChanges();

            return(Ok(tOrgCluster));
        }
Ejemplo n.º 5
0
        public ActionResult addNewcluster(tOrgCluster data, int tag)
        {
            if (data.clusterCode == null)
            {
                Random rnd    = new Random();
                var    suffix = rnd.Next(1, 999);
                do
                {
                    data.clusterCode = "CC" + DateTime.Now.ToString("yyMMddHHmmssfff") + (suffix.ToString("D3"));
                }while (HRIS.tOrgClusters.Any(e => e.clusterCode == data.clusterCode));

                HRIS.Entry(data).State = EntityState.Added;
            }
            else
            {
                HRIS.Entry(data).State = tag == 2 ? EntityState.Deleted : EntityState.Modified;
            }

            HRIS.SaveChanges();

            return(Json(data.clusterCode, JsonRequestBehavior.AllowGet));
        }