public ManagerResultViewModel DeleteRelation(SaleCharter _sc) { var _mrvm = new ManagerResultViewModel(); _mrvm.country = _sc.operatorCountry + " and " + _sc.merchantCountry + " respectively"; _mrvm.name = _sc.operatorName + " and " + _sc.merchantName; _mrvm.Entity = "Operator and Merchant"; _mrvm.OperationType = "deletion of relationshipbetween"; var _saleChannel = _db.saleChannel; var channel = from sc in _saleChannel where sc.merchantId == _sc.merchantId && sc.operatorId == _sc.operatorId select sc; if (!channel.Any()) { _mrvm.isSuccessful = false; _mrvm.reason = "as one of them doens't exist or no relation"; return(_mrvm); } _db.saleChannel.Remove(channel.ToList().First()); _db.SaveChanges(); _mrvm.isSuccessful = true; return(_mrvm); }
public ManagerResultViewModel createRelationShip(int MerchantId, int OperatorId) { var _mm = new MerchantManager(); var _om = new OperatorManager(); var _merchat = _mm.GetMerchant(MerchantId); //gets merchant object var _operator = _om.GetOperator(OperatorId); //gets operator object var _mrvm = new ManagerResultViewModel(); _mrvm.country = _operator.country + " and " + _merchat.country + " respectively"; _mrvm.name = _operator.name + " and " + _merchat.name; _mrvm.Entity = "Operator and Merchant"; _mrvm.OperationType = "creation of the relationship"; if (_merchat != null && _operator != null) { var channel = from sc in _db.saleChannel where sc.merchantId == MerchantId && sc.operatorId == OperatorId select sc; if (!channel.Any()) { _db.saleChannel.Add(new SaleChannel { merchantId = MerchantId, operatorId = OperatorId }); _mrvm.isSuccessful = true; _db.SaveChanges(); return(_mrvm); } } _mrvm.isSuccessful = false; _mrvm.reason = "the relationship already exists or operator and/or merchant don't exist"; return(_mrvm); }
public ManagerResultViewModel EditOperator(Operator op) { var _matchingOp = EntityExists(op); var _mrvm = new ManagerResultViewModel(); _mrvm.country = op.country; _mrvm.name = op.name; _mrvm.Entity = "Operator"; _mrvm.OperationType = "Editing"; var query = from Op in _db.Operators where Op.Id == op.Id select Op; if (query.Any()) { var Op = _db.Operators.Find(query.ToList().First().Id); if (Op.name != op.name || Op.country != op.country) { Op.country = op.country; Op.description = op.description; Op.name = op.name; Op.isDown = op.isDown; _db.Entry(Op).State = System.Data.Entity.EntityState.Modified; _db.SaveChanges(); _mrvm.isSuccessful = true; return(_mrvm); } } _mrvm.isSuccessful = false; _mrvm.reason = "as another Operator of the same name and country exists"; return(_mrvm); }
public ManagerResultViewModel DeleteOperator(int id) { var _matchingOp = _db.Operators.Find(id); var _mrvm = new ManagerResultViewModel(); _mrvm.country = _matchingOp.country; _mrvm.name = _matchingOp.name; _mrvm.Entity = "Operator"; _mrvm.OperationType = "deletion"; if (_matchingOp != null) { _db.Operators.Remove(_matchingOp); _db.SaveChanges(); _mrvm.isSuccessful = true; return(_mrvm); } _mrvm.isSuccessful = false; _mrvm.reason = "as the Operator does not exist"; return(_mrvm); }
public ManagerResultViewModel createOperator(Operator op) { var _matchingOp = EntityExists(op); var _mrvm = new ManagerResultViewModel(); _mrvm.country = op.country; _mrvm.name = op.name; _mrvm.Entity = "Operator"; _mrvm.OperationType = "Creation"; if (!_matchingOp.Any()) { _db.Operators.Add(op); _db.SaveChanges(); _mrvm.isSuccessful = true; return(_mrvm); } _mrvm.isSuccessful = false; _mrvm.reason = "as it already exists"; return(_mrvm); }