// create data center
        public bool AddDataCenter(DataCenterVM dataCenter, out string msg)
        {
            DataCenterLocation d = _context.DataCenterLocation.Where(a => a.Location == dataCenter.Location)
                                   .FirstOrDefault();

            if (d != null)
            {
                msg = "Data Center name already exist.";
                return(false);
            }
            try
            {
                DataCenterLocation newDataCenter = new DataCenterLocation();
                newDataCenter.Location = dataCenter.Location;
                _context.DataCenterLocation.Add(newDataCenter);
                _context.SaveChanges();
                msg = "Data Center successfully added";
                return(true);
            }
            catch
            {
                msg = "Failed to add data center.";
                return(false);
            }
        }
Example #2
0
        public ActionResult Edit(int id)
        {
            DataCenterVM dataCenter = _dRepo.GetDataCenter(id);

            if (dataCenter == null)
            {
                // if data center is null, redirect to index
                TempData["ErrorMsg"] = "Cannot edit this data center at the moment";
                return(RedirectToAction("Index"));
            }
            return(View(dataCenter));
        }
 // get data center by id
 public DataCenterVM GetDataCenter(int referenceID)
 {
     try
     {
         DataCenterVM dataCenter = _context.DataCenterLocation
                                   .Where(a => a.LocationID == referenceID)
                                   .Select(b => new DataCenterVM
         {
             Location   = b.Location,
             LocationID = b.LocationID,
         }).FirstOrDefault();
         return(dataCenter);
     }
     catch {
         return(null);
     }
 }
        // update data center
        public bool EditDataCenter(DataCenterVM dataCenter, out string msg)
        {
            DataCenterLocation d = _context.DataCenterLocation.Where(a => a.Location == dataCenter.Location).FirstOrDefault();

            if (d != null)
            {
                if (d.LocationID != dataCenter.LocationID)
                {
                    msg = "Data Center name already exist.";
                    return(false);
                }
            }
            DataCenterLocation original = _context.DataCenterLocation.Where(a => a.LocationID == dataCenter.LocationID).FirstOrDefault();
            bool changed = original.Location != dataCenter.Location;

            // check if any data center info changed
            if (changed)
            {
                try
                {
                    DataCenterLocation dataCenterUpdated = _context.DataCenterLocation
                                                           .Where(a => a.LocationID == dataCenter.LocationID)
                                                           .FirstOrDefault();
                    dataCenterUpdated.Location   = dataCenter.Location;
                    dataCenterUpdated.LocationID = dataCenter.LocationID;

                    _context.SaveChanges();
                    msg = "Data Center information succesfully updated.";
                    return(true);
                }
                catch
                {
                    msg = "Failed to update data center.";
                    return(false);
                }
            }
            else
            {
                msg = "Information is identical, no update performed.";
                return(false);
            }
        }
Example #5
0
        public ActionResult Edit(DataCenterVM model)
        {
            string msg = "";

            if (ModelState.IsValid)
            {
                bool success = _dRepo.EditDataCenter(model, out msg);
                if (success)
                {
                    TempData["SuccessMsg"] = msg;
                    return(RedirectToAction("Details", new { id = model.LocationID }));
                }
                else
                {
                    TempData["ErrorMsg"] = msg;
                }
            }
            DataCenterVM dataCenter = _dRepo.GetDataCenter(model.LocationID);

            return(View(dataCenter));
        }
Example #6
0
        public ActionResult Create(DataCenterVM model)
        {
            string msg = "";

            if (ModelState.IsValid)
            {
                bool success = _dRepo.AddDataCenter(model, out msg);
                if (success)
                {
                    TempData["SuccessMsg"] = msg;
                    return(RedirectToAction("index"));
                }
                else
                {
                    TempData["ErrorMsg"] = msg;
                }
            }
            else
            {
                TempData["ErrorMsg"] = "Data Center Location cannot be added at this time.";
            }
            return(View(model));
        }
Example #7
0
        public ActionResult Delete(DataCenterVM dataCenter)
        {
            string msg = "";

            if (ModelState.IsValid)
            {
                bool success = _dRepo.DeleteDataCenter(dataCenter.LocationID, out msg);
                if (success)
                {
                    TempData["SuccessMsg"] = msg;
                    return(RedirectToAction("index"));
                }
                else
                {
                    TempData["ErrorMsg"] = msg;
                }
            }
            else
            {
                TempData["ErrorMsg"] = "Data Center Location cannot be deleted at this time.";
            }

            return(View(dataCenter));
        }